package com.lifu.yygh.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lifu.yygh.common.result.Result;
import com.lifu.yygh.model.user.UserInfo;
import com.lifu.yygh.user.service.UserInfoService;
import com.lifu.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description
 * @Author lifu
 * @Date 2021/5/23 13:52
 */
@Api(tags = "用户认证后台管理接口")
@RestController
@RequestMapping(value = "/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @ApiOperation(value = "用户列表（条件查询带分页）")
    @GetMapping(value = "/{page}/{limit}")
    public Result list(@PathVariable long page,
                       @PathVariable long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page,limit);
        Page<UserInfo> userInfoPage = userInfoService.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(userInfoPage);
    }
    //用户锁定
    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(
            @PathVariable("userId") Long userId,
            @PathVariable("status") Integer status){
        userInfoService.lock(userId, status);
        return Result.ok();
    }
    //用户详情
    @GetMapping("show/{userId}")
    @ApiOperation(value = "用户详情")
    public Result show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }
    //认证审批
    @ApiOperation(value = "认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
